package com.yanqu.road.server.manger.maidian.restaurantroom;

import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.wineshop.WineShopBuilding;
import com.yanqu.road.entity.wineshop.UserWineShopBuilding;
import com.yanqu.road.entity.wineshop.UserWineShopData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.config.WineShopMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RestaurantRoomLog {

    public static final String RESTAURANT_ROOM = "restaurant_room";

    public static final String RESTAURANT_LEVEL = "restaurant_level";
    public static final String RESTAURANT_EAT = "restaurant_eat";
    public static final String RESTAURANT_PLAY = "restaurant_play";

    public static final String RESTAURANT_EATAREA = "restaurant_eatarea";
    public static final String RESTAURANT_EATNAME = "restaurant_eatname";
    public static final String RESTAURANT_EATLV = "restaurant_eatlv";
    public static final String VOCATION = "vocation";
    public static final String RESTAURANT_EATADD = "restaurant_eatadd";

    public static final String RESTAURANT_PLAYAREA = "restaurant_playarea";
    public static final String RESTAURANT_PLAYNAME = "restaurant_playname";
    public static final String RESTAURANT_PLAYLV = "restaurant_playlv";
    public static final String RESTAURANT_PLAYADD = "restaurant_playadd";


    public static void uploadSnapshot(GamePlayer player) {

        try {
            if (!DataAnalyticsMgr.openDataAnalytics()) return;

            DefaultEventTraceAction action = new DefaultEventTraceAction(RESTAURANT_ROOM, player);

            WineShopModule wineShopModule = player.getModule(WineShopModule.class);

            UserWineShopData userWineShopData = wineShopModule.getUserWineShopData();

            action.build(RESTAURANT_LEVEL, userWineShopData.getWineShopLv());

            //餐饮
            List<Map<String, Object>> objectGroup = new ArrayList<>();
            //娱乐
            List<Map<String, Object>> objectGroup2 = new ArrayList<>();

            for (Map.Entry<Integer, UserWineShopBuilding> buildingEntry : wineShopModule.getUserWineShopBuildingMap().entrySet()) {
                UserWineShopBuilding building = buildingEntry.getValue();
                WineShopBuilding buildingInfo = WineShopMgr.getWineShopBuilding(building.getId());
                if(buildingInfo == null){
                    continue;
                }
                //餐饮
                if(buildingInfo.getBigType() == 1){
                    Map<String, Object> map = new HashMap<>();
                    map.put(RESTAURANT_EATAREA, buildingInfo.getBigType());
                    map.put(RESTAURANT_EATNAME, buildingInfo.getId());
                    map.put(RESTAURANT_EATLV, building.getLv());

                    SkillInfo skillInfo = SkillMgr.getSkillInfo(Integer.parseInt(buildingInfo.getSkillId()));
                    if (skillInfo != null) {
                        int occupation = skillInfo.getParamList().get(2);
                        int addValue = SkillMgr.getSkillAddition(skillInfo, building.getLv());
                        map.put(VOCATION, occupation);
                        map.put(RESTAURANT_EATADD, addValue);
                    }
                    objectGroup.add(map);
                }else if(buildingInfo.getBigType() == 2){
                    //娱乐
                    Map<String, Object> map = new HashMap<>();
                    map.put(RESTAURANT_PLAYAREA, buildingInfo.getBigType());
                    map.put(RESTAURANT_PLAYNAME, buildingInfo.getId());
                    map.put(RESTAURANT_PLAYLV, building.getLv());

                    SkillInfo skillInfo = SkillMgr.getSkillInfo(Integer.parseInt(buildingInfo.getSkillId()));
                    if (skillInfo != null) {
                        int occupation = skillInfo.getParamList().get(2);
                        int addValue = SkillMgr.getSkillAddition(skillInfo, building.getLv());
                        map.put(VOCATION, occupation);
                        map.put(RESTAURANT_PLAYADD, addValue);
                    }
                    objectGroup2.add(map);
                }
            }
            action.build(RESTAURANT_EAT, objectGroup);
            action.build(RESTAURANT_PLAY, objectGroup2);

            action.trace();
        } catch (Exception e) {
            DataAnalyticsMgr.getLogger().error(" error ", e);
        }

    }
}
